# -*- coding: utf-8 -*-
# __author__:鲍盈廷
# 2020-04-25
# !/usr/bin/python

import random

from pprint import pprint

# ----------------图片---------------------------------
img1 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss23b715e0f5c6eb68995c72d98be45567(720x1280).jpeg';
img2 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss3f5ad86928f0e5b86e74c7f96902172d(640x368).jpeg';
img3 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss91c217a8d3d187c5f1b0eef9ed047da1(720x1280).jpeg';
img4 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss65d4e45eba803602ebebc1a993a6fb7e(720x1280).jpeg';
img5 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss7c90a898fc70f87fd00cc39c2de490da(640x960).jpeg';
img6 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlbossb9f966162c12e2892a4196c3951551cd(640x960).jpeg';
img7 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss698dbd7b1e84d584d0a6ce93ba145e7d(540x1140).jpeg';
img8 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss136de4b8ab54e6673a87fed9313061e1(3024x4032).jpeg';
img9 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss557281ae7a943405853d74df804afbd3(720x1280).jpeg';
img10 = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss8a04a863201639b587bb4322d0fd25f2(1242x2208).jpeg';
IMAGE = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss8a04a863201639b587bb4322d0fd25f2(1242x2208).jpeg';
jpg = 'https://dummyimage.com/200x200.jpg?text=0';
png = 'https://dummyimage.com/200x200.png?text=0';
gif = 'https://dummyimage.com/200x200.gif?text=0';
bmp = 'https://dummyimage.com/200x200.bmp?text=0';
jpeg = 'https://dummyimage.com/200x200.jpeg?text=0'

img_dict = {'IMAGE': '', 'img1': img1, 'img2': img2, 'img3': img3,
            'img4': img4, 'img5': img5, 'img7': img7, 'img8': img8, 'img9': img9, 'img10': img10,
            'bmp': bmp, 'jpg': jpg, 'gif': gif, 'png': png, 'jpeg': jpeg}
# ----------------视频---------------------------------
VIDEO = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlbossc84ce4136556b55295ff9423140fa9a0(600x800)(15040ms).mp4'
vedio = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlbossc84ce4136556b55295ff9423140fa9a0(600x800)(15040ms).mp4';
vedio_1m = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss874c7a51165cf7d116449ecee264254e(640x360)(60186ms).mp4'
vedio_15s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss716e208611cda548580c9314fbe4d7b2(720x960)(15104ms).mp4'
vedio_width = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlbossc5e0c2cb9fa66082bf39e97013eb5604(1280x720).mp4'
vedio_2m59s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss1c356ac3bac11e0d0ffe9ca00c69d91a(540x960)(179560ms).mp4'
vedio_3m3s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss44c394d2222531ba5dd3928cab60ad56(480x640)(183317ms).mp4'
vedio_dict = {'VIDEO': '', 'vedio_2m59s': vedio_2m59s, 'vedio_3m3s': vedio_3m3s, 'vedio': vedio,
              'vedio_1m': vedio_1m, 'vedio_15s': vedio_15s, 'vedio_width': vedio_width}
# ----------------语音---------------------------------
VOICE = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss1096ca685113ae2bee7d9be9c4b773d3.mp3'
voice_31s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss1096ca685113ae2bee7d9be9c4b773d3.mp3';
voice_2m = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss2198841bdc83595fb82af731f32cc196.mp3'
voice_10s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlboss38994fa49fa9d42bdac6a6afe2e81675.mp3'
voice_5s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlbossf4824686a1eff0bf9885659802555f99.mp3'
voice_66s = 'https://images2.bestjlb.com/jlbapp/1b4a80cf6973c82ccc3527503de01297/2020/04/v2jlbossf4cb027018631f31c660987c9e010e08.mp3'

voice_dict = {'VOICE': '', 'voice_31s': voice_31s,
              'voice_2m': voice_2m, 'voice_10s': voice_10s, 'voice_66s': voice_66s}


# 将传入的字符串变成list
def change_list(type):
    type = type.split('&')
    return list(type)


# 生成图片或视频文件
def Create_Attachments(types, counts):
    """
    :param types: 附件类型,如类型有语音，视频，输入格式"IMAGE&VIDEO&VOICE"
    :param counts: 每种附件类型的数量，，如图片3张，视频1个，语音1个，输入格式"3&1&1
    :return:返回附件
    """
    types = change_list(types)
    count = change_list(counts)
    attachments = []
    for type in types:
        print(type)
        if type in img_dict.keys():
            create_img(attachments, type, count[0])
        elif type in vedio_dict.keys():
            create_video(attachments, type, count[1])
        elif type in voice_dict.keys():
            create_voice(attachments, type, count[2])
    return attachments


# 生成图片文件
def create_img(attachments, type, count):
    count = int(count)
    while count != 0:
        if type == 'IMAGE':
            file = {"fileUrl": random.choice(list(img_dict.values())), "type": "IMAGE"}
        else:
            file = {"fileUrl": img_dict[type], "type": "IMAGE"}
        attachments.append(file)
        count = count - 1
    return attachments


# 生成视频文件
def create_video(attachments, type, count):
    count = int(count)
    while count != 0:
        if type == 'VIDEO':
            file = {"fileUrl": random.choice(list(vedio_dict.values())), "type": "VIDEO"}
        else:
            file = {"fileUrl": vedio_dict[type], "type": "VIDEO"}
        count = count - 1
        attachments.append(file)
    return attachments


# 生成语音文件
def create_voice(attachments, type, count):
    count = int(count)
    while count != 0:
        if type == 'VOICE':
            file = {"fileUrl": random.choice(list(voice_dict.values())), "type": "VOICE"}
        else:
            file = {"fileUrl": voice_dict[type], "type": "VOICE"}
        attachments.append(file)
        count = count - 1
    return attachments


# 固定格式图片
def create_img_form(type, form):
    if type == 'IMAGE':
        file = img_dict[form]
    else:
        file = img_dict[IMAGE]
    return file


if __name__ == '__main__':
    a = Create_Attachments("VIDEO&IMAGE&VOICE", "5&1&1")
    print(type(a))
    pprint(a)